<template>
  <Header :title="{ zh: '印线区目视管理看板', en: 'Printing Area Visual Board', index: 7 }" />

  <div class="EchartsContainer">
    <swiper :autoplay="{
      delay: 60000
    }" :slides-per-view="1" :space-between="2000" style="height: 50%">
      <swiper-slide>
        <div class="row" style="height: 100%;">
          <div class="item">
            <div class="title">1#印线机</div>
            <div class="echarts" id="main"></div>
          </div>
          <div class="item">

            <div class="title">2#印线机</div>
            <div class="echarts" id="main2"></div>
          </div>
        </div>
      </swiper-slide>
      <swiper-slide>
        <div class="row" style="height: 100%;">
          <div class="item">
            <div class="title">3#印线机</div>
            <div class="echarts" id="main3"></div>
          </div>
          <div class="item">
            <div class="title">4#印线机</div>
            <div class="echarts" id="main7"></div>
          </div>
        </div>
      </swiper-slide>
    </swiper>

    <swiper :autoplay="{
      delay: 60000
    }" :slides-per-view="1" :space-between="2000" style="height: 50%">
      <swiper-slide>
        <div class="row" style="margin-top: 10px; width: 100%; height: 100%">
          <div class="item">
            <div class="title">1#印线机</div>
            <div class="echarts" id="main4"></div>
          </div>
        </div>
      </swiper-slide>
      <swiper-slide>
        <div class="row" style="margin-top: 10px; width: 100%; height: 100%">
          <div class="item">
            <div class="title">2#印线机</div>
            <div class="echarts" id="main5"></div>
          </div>
        </div>
      </swiper-slide>
      <swiper-slide>
        <div class="row" style="margin-top: 10px; width: 100%; height: 100%">
          <div class="item" style="padding-bottom: 20px">
            <div class="title">3#印线机</div>
            <div class="echarts" id="main6"></div>
          </div>
        </div>
      </swiper-slide>
      <swiper-slide>
        <div class="row" style="margin-top: 10px; width: 100%; height: 100%">
          <div class="item" style="padding-bottom: 20px">
            <div class="title">4#印线机</div>
            <div class="echarts" id="main8"></div>
          </div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script setup lang="ts">
import { nextTick, onMounted, ref } from 'vue'
import Header from '../components/Header.vue'
import * as echarts from 'echarts'
import { ElMessage } from 'element-plus'
import request from '@/utils/request'
import { Swiper, SwiperSlide } from 'swiper/vue'

const showData = ref([
  {
    data: [
      {
        name: '停机时间',
        type: 'bar',
        data: [30],
        color: '#FF0000',
        barWidth: '10%',
        barGap: '100%',
        label: {
          show: true,
          position: 'right'
        }
      },
      {
        name: '开机时间',
        type: 'bar',
        data: [300],
        color: '#93BEFF',
        barWidth: '10%',
        barGap: '200%',
        label: {
          show: true,
          position: 'right'
        }
      }
    ]
  },
  {
    data: [
      {
        name: '停机时间',
        type: 'bar',
        data: [0],
        color: '#FF0000',
        barWidth: '10%',
        barGap: '100%',
        label: {
          show: true,
          position: 'right'
        }
      },
      {
        name: '开机时间',
        type: 'bar',
        data: [300],
        color: '#75DDB3',
        barWidth: '10%',
        barGap: '200%',
        label: {
          show: true,
          position: 'right'
        }
      }
    ]
  },
  {
    data: [
      {
        name: '停机时间',
        type: 'bar',
        data: [25],
        color: '#FF0000',
        barWidth: '10%',
        barGap: '100%',
        label: {
          show: true,
          position: 'right'
        }
      },
      {
        name: '开机时间',
        type: 'bar',
        data: [300],
        barWidth: '10%',
        barGap: '200%',
        color: '#BFBFBF',
        label: {
          show: true,
          position: 'right'
        }
      }
    ]
  }, {
    data: [
      {
        name: '停机时间',
        type: 'bar',
        data: [40],
        color: '#FF0000',
        barWidth: '10%',
        barGap: '100%',
        label: {
          show: true,
          position: 'right'
        }
      },
      {
        name: '开机时间',
        type: 'bar',
        data: [300],
        barWidth: '10%',
        barGap: '200%',
        color: '#BFBFBF',
        label: {
          show: true,
          position: 'right'
        }
      }
    ]
  }
]) as any
const monthData = ref([
  {
    xData: [1, 2, 3, 4, 5,],
    Data: [92, 95, 88, 90, 90,]
  },
  {
    xData: [1, 2, 3, 4, 5,],
    Data: [92, 94, 92, 92, 100]
  },
  {
    xData: [1, 2, 3, 4, 5,],
    Data: [94, 96, 93, 87, 92]
  },
  {
    xData: [1, 2, 3, 4, 5,],
    Data: [81, 85, 83, 82, 87]
  },

]) as any
const getData = async () => {
  // // 获取当日开关机数据
  // try {
  //   let tableDataList = (await request.post<any, any>(
  //     `/macMgt/show/query?macType=${'印线机'}`
  //   )) as any
  //   tableDataList.forEach((item: any, index: any) => {
  //     showData.value[index].data[0].data.push(item.end)
  //     showData.value[index].data[1].data.push(item.start)
  //   })
  // } catch (error: any) {
  //   ElMessage.error(error)
  // }

  // // 获取当月开关机数据
  // try {
  //   let macName = encodeURIComponent('1#印线机')
  //   let tableDataList = (await request.post<any, any>(
  //     `/macMgt/show/query/showMonQuery?macType=${''}&macName=${macName}`
  //   )) as any
  //   tableDataList.forEach((item: any, index: any) => {
  //     monthData.value[0].xData.push(item.reDate)
  //     monthData.value[0].Data.push(item.rate)
  //   })
  // } catch (error: any) {
  //   ElMessage.error(error)
  // }

  // try {
  //   let macName2 = encodeURIComponent('2#印线机')
  //   let tableDataList = (await request.post<any, any>(
  //     `/macMgt/show/query/showMonQuery?macType=${''}&macName=${macName2}`
  //   )) as any
  //   tableDataList.forEach((item: any, index: any) => {
  //     monthData.value[1].xData.push(item.reDate)
  //     monthData.value[1].Data.push(item.rate)
  //   })
  // } catch (error: any) {
  //   ElMessage.error(error)
  // }

  // try {
  //   let macName3 = encodeURIComponent('3#印线机')
  //   let tableDataList = (await request.post<any, any>(
  //     `/macMgt/show/query/showMonQuery?macType=${''}&macName=${macName3}`
  //   )) as any
  //   tableDataList.forEach((item: any, index: any) => {
  //     monthData.value[2].xData.push(item.reDate)
  //     monthData.value[2].Data.push(item.rate)
  //   })
  // } catch (error: any) {
  //   ElMessage.error(error)
  // }

  // try {
  //   let macName4 = encodeURIComponent('4#印线机')
  //   let tableDataList = (await request.post<any, any>(
  //     `/macMgt/show/query/showMonQuery?macType=${''}&macName=${macName4}`
  //   )) as any
  //   tableDataList.forEach((item: any, index: any) => {
  //     monthData.value[3].xData.push(item.reDate)
  //     monthData.value[3].Data.push(item.rate)
  //   })
  // } catch (error: any) {
  //   ElMessage.error(error)
  // }
}

onMounted(async () => {
  await getData()
  getEchartsDom()
})

const getEchartsDom = () => {
  let chartDom = document.getElementById('main')
  let myChart = echarts.init(chartDom)
  let option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    legend: {
      top: 'bottom'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '18%',
      top: '5%',
      containLabel: true
    },
    xAxis: {
      type: 'value',
      boundaryGap: [0, 0.01]
    },
    yAxis: {
      type: 'category',
      data: [' ']
    },

    series: showData.value[0].data
  }
  option && myChart.setOption(option)

  let chartDom2 = document.getElementById('main2')
  let myChart2 = echarts.init(chartDom2)
  let option2 = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    legend: {
      top: 'bottom'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '18%',
      top: '5%',
      containLabel: true
    },
    xAxis: {
      type: 'value',
      boundaryGap: [0, 0.01]
    },
    yAxis: {
      type: 'category',
      data: [' ']
    },

    series: showData.value[1].data
  }
  option2 && myChart2.setOption(option2)

  let chartDom3 = document.getElementById('main3')
  let myChart3 = echarts.init(chartDom3)
  let option3 = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    legend: {
      top: 'bottom'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '18%',
      top: '5%',
      containLabel: true
    },
    xAxis: {
      type: 'value',
      boundaryGap: [0, 0.01]
    },
    yAxis: {
      type: 'category',
      data: [' ']
    },

    series: showData.value[2].data
  }
  option3 && myChart3.setOption(option3)

  let chartDom7 = document.getElementById('main7')
  let myChart7 = echarts.init(chartDom7)
  let option7 = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    legend: {
      top: 'bottom'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '18%',
      top: '5%',
      containLabel: true
    },
    xAxis: {
      type: 'value',
      boundaryGap: [0, 0.01]
    },
    yAxis: {
      type: 'category',
      data: [' ']
    },

    series: showData.value[3].data
  }
  option7 && myChart7.setOption(option7)

  let chartDom4 = document.getElementById('main4')
  let myChart4 = echarts.init(chartDom4)
  let option4 = {
    legend: {
      data: ['稼动率'],
      top: 'bottom'
    },
    grid: {
      left: 20,
      right: 20,
      bottom: 40,
      top: 30,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: monthData.value[0].xData
    },
    yAxis: {
      type: 'value'
    },
    tooltip: {
      trigger: 'axis'
    },
    series: [
      {
        name: '稼动率',
        data: monthData.value[0].Data,
        type: 'line',
        label: {
          show: true,
          position: 'top'
        },
        color: '#FAC858'
      }
    ]
  }
  option4 && myChart4.setOption(option4)

  // 第五张图
  let chartDom5 = document.getElementById('main5')
  let myChart5 = echarts.init(chartDom5)
  let option5 = {
    legend: {
      data: ['稼动率'],
      top: 'bottom'
    },
    xAxis: {
      type: 'category',
      data: monthData.value[1].xData
    },
    grid: {
      left: 20,
      right: 20,
      bottom: 40,
      top: 30,
      containLabel: true
    },
    yAxis: {
      type: 'value'
    },
    tooltip: {
      trigger: 'axis'
    },
    series: [
      {
        name: '稼动率',
        data: monthData.value[1].Data,
        type: 'line',
        label: {
          show: true,
          position: 'top'
        },
        color: '#72DDB3'
      }
    ]
  }
  option5 && myChart5.setOption(option5)

  // 第六张图
  let chartDom6 = document.getElementById('main6')
  let myChart6 = echarts.init(chartDom6)
  let option6 = {
    legend: {
      data: ['稼动率'],
      top: 'bottom'
    },
    grid: {
      left: 20,
      right: 20,
      bottom: 40,
      top: 30,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: monthData.value[2].xData
    },
    yAxis: {
      type: 'value'
    },
    tooltip: {
      trigger: 'axis'
    },
    series: [
      {
        name: '稼动率',
        data: monthData.value[2].Data,
        type: 'line',
        label: {
          show: true,
          position: 'top'
        },
        color: '#93BEFF'
      }
    ]
  }
  option6 && myChart6.setOption(option6)

  // 最后一张图
  let chartDom8 = document.getElementById('main8')
  let myChart8 = echarts.init(chartDom8)
  let option8 = {
    legend: {
      data: ['稼动率'],
      top: 'bottom'
    },
    grid: {
      left: 20,
      right: 20,
      bottom: 40,
      top: 30,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: monthData.value[3].xData
    },
    yAxis: {
      type: 'value'
    },
    tooltip: {
      trigger: 'axis'
    },
    series: [
      {
        name: '稼动率',
        data: monthData.value[3].Data,
        type: 'line',
        label: {
          show: true,
          position: 'top'
        },
        color: '#93BEFF'
      }
    ]
  }
  option8 && myChart8.setOption(option8)
}

onMounted(() => {
  getEchartsDom()
  function One() {
    if (location.href.indexOf('#reloaded') == -1) {
      location.href = location.href + '#reloaded'
      location.reload()
    }
  }
  One()
})
</script>

<style scoped lang="less">
.EchartsContainer {
  border-radius: 4px;
  margin-top: 10px;
  width: 100%;
  height: calc(100vh - 7vh - 40px);
}

.row {
  display: flex;
  height: 50%;
  width: 100%;

  .item {
    background-color: white;
    width: 100%;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-bottom: 20px !important;
    padding: 0 10px 5px;

    // align-items: center;
    .title {
      font-weight: 900;
      font-size: 1rem;
      margin-top: 10px;
      text-align: center;
      color: black;
    }

    .echarts {
      flex: 1;
    }
  }
}

:deep(thead) {
  .is-center {
    color: white;
    background-color: #ff9940;
  }
}
</style>
